#!/bin/bash

jarName=$1
remoteFloder=$2
jvmOps=${@:3}

echo ${jarName}
echo ${remoteFloder}
echo ${jvmOps}

PID=$(ps -ef | grep  ${jarName}.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
    echo Application is already stopped
else
    echo kill $PID
    kill -9 $PID
fi

echo start....

/usr/local/jdk/bin/java ${jvmOps} -Xloggc:/opt/${jarName}-gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/${jarName}.dump -Dfile.encoding=UTF-8 -jar ${remoteFloder}/${jarName}.jar  --spring.profiles.active=prod > /dev/null 2>&1 &